﻿using Config;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using UI.TestModule;
using System.IO;
using Communication.Model.speedData;
using Communication.Model.netPacket;
using Communication.Model.packetType;
using Communication.Model.displacement;
using Communication.Model.acceleration;
using Communication.Model.configuration;
using Communication.Model.slowSignal;
using Communication.TcpIpService;
using Communication.Model.speedRealTVol;
using Communication.Interface;
using UI.Models;
using System.Threading;

namespace UI
<<<<<<< HEAD
{   //成员变量定义，保留和界面按键相关的函数
=======
{
    //图形界面自动生成的操作逻辑函数
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
    public partial class MainForm : Form
    {
        #region 成员变量
        //缓存加速度实时数据
        AccData accDataNow;
        Task refreshtask;
<<<<<<< HEAD
        //不储存数据
        Boolean save=false;
=======

>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        Dictionary<int, ChannelType> TypeDictionary = new Dictionary<int, ChannelType>()
        { { 0, ChannelType.Displacement}, { 1, ChannelType.None },{ 2, ChannelType.Acceleration} };
        //private TreeNode config;
        Settings settings = new Settings();
        //通信类
        //ClientManager _iCommunicationService = new ClientManager();
        ICommunicationService _iCommunicationService = new CommunicationService();
<<<<<<< HEAD
        public int DisplacementNo = 0;        
        public int AccNo = 0;
=======

>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        string IP = "127.0.0.1";
        int Port = 3000;
        int dpt_point_num = 1024;
        //实时数据
        SpeedData speed_now = new SpeedData();
        //数据存储
        int FlagSave = 0;
        string PathSave = "";
        //0:监测模式；1：测试模式
        int Mode = 0;
        //0000 0000结束数据
        //0000 0001开始数据
        //0000 0010调试模式
        //0000 0000运行模式（结束数据）
        byte ModeEnable = 0x00;
        TestHelper testHelper = new TestHelper();
        TestForm testForm = null;
        //图谱坐标
        AxisYUnit axisYUnit = AxisYUnit.db;

        //选择的测点
        int testpoint = 1;
<<<<<<< HEAD
        //报警使能设置数组
        int[,] enablesetting = new int[32, 8];
        //报警数值设置数组
        float[,] alarmvalue = new float[32, 16];
        #endregion
        //批量修改配置数组
        int[] batched = new int[32];
        string foldPath = null;
    
=======
        #endregion

>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        public MainForm()
        {
            InitializeComponent();
            //config = DAQ;
            //Initial(DAQ);
            Initial();
<<<<<<< HEAD
=======
            
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        }
        private void Initial()
        {
            //chart1.ChartAreas[1].CursorX.IsUserSelectionEnabled = true;
            //chart1.ChartAreas[1].Axes[0].Minimum = 1;
            //chart1.ChartAreas[1].Axes[0].Maximum = 200;
            ////游标1
            //float[] cursor1_x = new float[128];
            //float[] cursor1_y = new float[128];
            //Random rd = new Random();
            //for (int i=0;i<cursor1_x.Length;i++)
            //{
            //    cursor1_x[i] = i; 
            //    cursor1_y[i] = rd.Next(0, 100);
            //}
            //chart1.Series[1].Points.DataBindXY(cursor1_x, cursor1_y);
            ////游标2
            //float[] cursor2_x = new float[] { 1000, 1000 };
            //float[] cursor2_y = new float[] { 0, 100 };
            //chart1.Series[3].Points.DataBindXY(cursor2_x, cursor2_y);
            //chart1.ChartAreas[1].CursorX.SetSelectionPosition(1, 100);
            cb_filter.SelectedIndex = 0;
            cb_orbitID.SelectedIndex = 0;
        }

<<<<<<< HEAD
        private void 加载配置文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            OpenFileDialog dialog = new OpenFileDialog();
            string file = "";
            dialog.Multiselect = true;//该值确定是否可以选择多个文件
            dialog.Title = "请选择文件夹";
            dialog.Filter = "配置文件(*.xml)|*.xml";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                file = dialog.FileName;
            }
            bool Loaded = settings.Open(file);
            if (Loaded)
            {
                ProgressBar(10);
                settings.Path = file;
                GetChTypeNo();//统计通道类型数量
                //初始化各个界面
                GetBatchedChannel();
                SetGeneral();
                SetChartForm();
                SetConfigForm();
                SetDataGridForm();
                SetOctaveForm();
                //初始化转速波形界面
                SetRpmTimeWave();
                //使能按钮
                menuStrip1.Items[1].Enabled = true;
                IP = settings.SystemSet.IP;
                Port = settings.SystemSet.Port;
                //统计报警使能信息
                //顺序 高频段 低频段 全频段 标志位 通频阈值 1倍 2倍 0.5倍
                Getenablesetting();
                //统计报警值设定信息
                GetAlarmValue();
                //统计批量修改信息
                GetBatchedChannel();




            }
        }
      

=======
        /*
        public void UpdateGeneral()
        {

        }
        */
        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void 加载配置文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
            OpenFileDialog dialog = new OpenFileDialog();//winform加载文件类
            string file = "";//定义文件名为空
            dialog.Multiselect = true;//该值确定是否可以选择多个文件
            dialog.Title = "请选择文件夹";
            dialog.Filter = "配置文件(*.xml)|*.xml";//过滤器，确保只上传xml文件
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                file = dialog.FileName;//获得文件绝对路径+文件名
                

             //  MessageBox.Show(file);
              //  FileInfo fileInfo = new FileInfo(file); //实例化传入的配置文件信息
             //   string filename = fileInfo.Name;  //提取文件名
             //   MessageBox.Show(filename);
            }
            bool Loaded = settings.Open(file);  //解析文件并返回结果
            if (Loaded)
            {   // 子线程解析进度条
                progressBar1.Maximum = 100;
                //控件清0
                progressBar1.Value = 0;
                //创建线程
                Thread th = new Thread(Start3);
                //设置线程为背景线程
                th.IsBackground = true;
                th.Start();
                settings.Path = file;               
                GetChTypeNo();//统计通道类型数量
                //初始化各个界面
                SetGeneral();  //初始化总体界面
                SetChartForm();//初始化频谱界面
                SetDataGridForm();//初始化数据列表界面
                SetConfigForm(); //初始化配置界面              
                SetOctaveForm();//初始化1/3频程界面
                SetRotateForm();//初始化转速波形界面
        
                menuStrip1.Items[1].Enabled = true;
                IP = settings.SystemSet.IP;
                Port = settings.SystemSet.Port;
            }
            
        }

       

       
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895

        private void tableLayoutPanel1_Paint(object sender, PaintEventArgs e)
        {

        }

<<<<<<< HEAD
        private void 连接硬件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IP = settings.SystemSet.IP;
            Port = settings.SystemSet.Port;
            bool isConnnected = _iCommunicationService.Connect2Server(IP, Port);
            ProgressBar(80);
            if (isConnnected)
            {
                
=======
       
        private void 连接硬件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            progressBar1.Maximum = 100;
            //控件清0
            progressBar1.Value = 0;
            //创建线程
            Thread th = new Thread(Start1);
            //设置线程为背景线程
            th.IsBackground = true;
            th.Start();
            

            IP = settings.SystemSet.IP;
            Port = settings.SystemSet.Port;
            bool isConnnected = _iCommunicationService.Connect2Server(IP, Port);

            if (isConnnected)
            {
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
                _iCommunicationService.AddDataHandler(onDataReceived);
                _iCommunicationService.StartData();

                //refreshtask = Task.Run(() =>
                //  {
                //      while (true)
                //      {
                //          if (accDataNow.CHAccData != null)
                //          {
                //              for (int i = 0; i < accDataNow.CHAccData.Length; i++)
                //              {
                //                  Random rd = new Random();
                //                  accDataNow.CHAccData[i].TotalDB += (Convert.ToSingle(rd.Next(100)) / 1000.0f);
                //              }
                //              ReceivedAccData(accDataNow);
                //              Thread.Sleep(5000);
                //          }
                //      }
                //  });

                menuStrip1.Items[2].Enabled = true;
            }
<<<<<<< HEAD
=======

>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        }
        /// <summary>
        /// 收到采集数据
        /// </summary>
        /// <param name="netPacket"></param>
<<<<<<< HEAD
       
       

        private void 开始数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ProgressBar(10);
=======
        private void GetNetPakcetHandler(NetPacket packet)
        {
            //存储公有信息

            //更新总貌图
            UpdateGeneral(packet);
            //更新图表

            //更新数据列表

        }
        /// <summary>
        /// 更新总貌图
        /// </summary>
        /// <param name="packet"></param>
        
        /// <summary>
        /// 收到数据后，更新图谱
        /// </summary>
        /// <param name="packet"></param>
        private void UpdateChart(int type)
        {
            //if (chart1.IsHandleCreated && chart1.InvokeRequired)
            //{
            //    chart1.Invoke(new Action<>(SetComboIndex));
            //    return;
            //}

        }
       
       
        private void kaiToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 开始数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
            _iCommunicationService.StartData();
            //menuStrip1.Items[3].Enabled = true;
            //ModeEnable = Convert.ToByte(ModeEnable | 0b00000001);
            //if ((ModeEnable & 0b00000011) == 3)
            //    menuStrip1.Items[4].Enabled = true;
        }

        private void 结束数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
<<<<<<< HEAD
            ProgressBar(10);
=======
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
            _iCommunicationService.StopData();
            //menuStrip1.Items[3].Enabled = false;
            //ModeEnable = Convert.ToByte(ModeEnable & 0b11111110);
        }

        private void 调试模式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
<<<<<<< HEAD
            ProgressBar(10);
            _iCommunicationService.DebugMode();
            //ModeEnable = Convert.ToByte(ModeEnable | 0b00000010);
            //if ((ModeEnable & 0b00000011) == 3)
            //    menuStrip1.Items[4].Enabled = true;
=======
          _iCommunicationService.DebugMode();
            ModeEnable = Convert.ToByte(ModeEnable | 0b00000010);
            if ((ModeEnable & 0b00000011) == 3)
                menuStrip1.Items[4].Enabled = true;
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        }

        private void label42_Click(object sender, EventArgs e)
        {

        }

        private void tabPage9_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 应用修改的配置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
<<<<<<< HEAD
            ProgressBar(10);
=======
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
            SaveSettings();
        }

       
<<<<<<< HEAD
     
      
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateConfigForm();
        }
=======
        private void SetSelectecIndexOfListBox()
        {
            if (_listBox != null)
            {
                _listBox.SelectedIndex = _selectedIndex;
            }
        }
    
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
           // MessageBox.Show("加载初始配置信息");
            UpdateConfigForm();
        }
  
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        /// <summary>
        /// 向下位机传输配置文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
<<<<<<< HEAD
=======
        //下传配置
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        private void button1_Click(object sender, EventArgs e)
        {
            label1.Text = "";
            DialogResult MsgBoxResult;//设置对话框的返回值
            MsgBoxResult = MessageBox.Show("将改变下位机整体配置，存在风险，是否执行？",//对话框的显示内容 
            "提示",//对话框的标题 
            MessageBoxButtons.YesNo,//定义对话框的按钮，这里定义了YSE和NO两个按钮 
            MessageBoxIcon.Exclamation,//定义对话框内的图表式样，这里是一个黄色三角型内加一个感叹号 
            MessageBoxDefaultButton.Button2);//定义对话框的按钮式样
            if (MsgBoxResult == DialogResult.Yes)//如果对话框的返回值是YES（按"Y"按钮）
            {
<<<<<<< HEAD
               this.label1.ForeColor = System.Drawing.Color.Red;//字体颜色设定
                label1.Text = " 你选择了按下”Yes“的按钮！";


=======
                this.label1.ForeColor = System.Drawing.Color.Red;//字体颜色设定
                label1.Text = " 你选择了按下”Yes“的按钮！";

                progressBar1.Maximum = 100;
                //控件清0
                progressBar1.Value = 0;
                //创建线程
                Thread th = new Thread(Start2);
                //设置线程为背景线程
                th.IsBackground = true;
                th.Start();
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895




                string uploadPath = settings.SystemSet.UploadFilePath;  //从配置文件里获取配置文件存放在下位机的路径
                string userName = settings.SystemSet.UserName;  //从配置文件里获取用户名
                string key = settings.SystemSet.Key;  //从配置文件里获取密码
                FtpService ftp = new FtpService(IP.ToString(), uploadPath, userName, key);

                MessageBox.Show("正在上传，请稍后");
                ftp.UploadFile(settings.Path);//传入的是文件路径+文件名
                MessageBox.Show("上传成功，正在验证配置文件大小，请稍后");
                long filesize = ftp.GetFileSize(settings.Path);
<<<<<<< HEAD
                MessageBox.Show("当前配置文件大小为" + Convert.ToString(filesize / 1024) + "KB");
            }
            if (MsgBoxResult == DialogResult.No)//如果对话框的返回值是NO（按"N"按钮）
            {
               this.label1.ForeColor = System.Drawing.Color.Blue;//字体颜色设定
                label1.Text = " 你选择了按下”No“的按钮！";
            }

        }



=======
                MessageBox.Show("当前配置文件大小为" + Convert.ToString(filesize/1024)+"KB");
            }
            if (MsgBoxResult == DialogResult.No)//如果对话框的返回值是NO（按"N"按钮）
            {
                this.label1.ForeColor = System.Drawing.Color.Blue;//字体颜色设定
                label1.Text = " 你选择了按下”No“的按钮！";
            }
            

        }

        //下载配置文件
        private void button3_Click(object sender, EventArgs e)
        {
            string uploadPath = settings.SystemSet.UploadFilePath;  //从配置文件里获取配置文件存放在下位机的路径
            string userName = settings.SystemSet.UserName;  //从配置文件里获取用户名
            string key = settings.SystemSet.Key;  //从配置文件里获取密码
            FtpService ftp = new FtpService(IP.ToString(), uploadPath, userName, key);


           

        }
        //删除配置
        private void button4_Click(object sender, EventArgs e)
        {
            string uploadPath = settings.SystemSet.UploadFilePath;  //从配置文件里获取配置文件存放在下位机的路径
            string userName = settings.SystemSet.UserName;  //从配置文件里获取用户名
            string key = settings.SystemSet.Key;  //从配置文件里获取密码
            FtpService ftp = new FtpService(IP.ToString(), uploadPath, userName, key);//建立连接
            ftp.Delete(settings.Path);//执行删除
            MessageBox.Show("配置文件已删除");

        }
        /*
        //验证配置大小
        private void button5_Click(object sender, EventArgs e)
        {
            string uploadPath = settings.SystemSet.UploadFilePath;  //从配置文件里获取配置文件存放在下位机的路径
            string userName = settings.SystemSet.UserName;  //从配置文件里获取用户名
            string key = settings.SystemSet.Key;  //从配置文件里获取密码
            FtpService ftp = new FtpService(IP.ToString(), uploadPath, userName, key);
            long filesize = ftp.GetFileSize(settings.Path);
            MessageBox.Show("当前配置文件大小为"+Convert.ToString(filesize));
        }
        */

>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateConfigForm();
        }


        private void 设置虚拟转速ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //_iCommunicationService.sendString("192.168.2.64", "SetVisualRate");
        }

        private void 运行模式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _iCommunicationService.RunMode();
            ModeEnable = Convert.ToByte(ModeEnable & 11111101);
        }

        private void label39_Click(object sender, EventArgs e)
        {

        }

        private void label40_Click(object sender, EventArgs e)
        {

        }
        //鼠标左键按下：设置选择区域的start坐标
        private void chart1_MouseDown(object sender, MouseEventArgs e)
        {
            chart1.ChartAreas[1].CursorX.SelectionStart = chart1.ChartAreas[1].CursorX.Position;
            chart1.ChartAreas[1].CursorX.SelectionEnd = chart1.ChartAreas[1].CursorX.SelectionStart;
        }
        //鼠标左键抬起：设置选择区域的end坐标
        private void chart1_MouseUp(object sender, MouseEventArgs e)
        {
            chart1.ChartAreas[1].CursorX.SelectionEnd = chart1.ChartAreas[1].CursorX.Position;
            DataPoint dp = getMaxPoint(chart1.Series[1].Points, chart1.ChartAreas[1].CursorX.SelectionStart, chart1.ChartAreas[1].CursorX.SelectionEnd);
            if (dp != null)
            {
                //画出最大值点
                //chart1.Series[2].Points.Clear();
                chart1.Series[2].Points.DataBindXY(new double[] { dp.XValue }, new double[] { dp.YValues[0] });
                //显示游标值
                SetControlText(label67, string.Format("{0:F2}Hz-{1:F2}Hz最大值",
                    chart1.ChartAreas[1].CursorX.SelectionStart, chart1.ChartAreas[1].CursorX.SelectionEnd));
                //显示区间内最大值
                SetControlText(textBox2, string.Format("{0:F2}dB@{1:F2}Hz", dp.YValues[0], dp.XValue));
            }
        }
        //chart1.GetToolTipText += new EventHandler<ToolTipEventArgs>(chart_GetToolTipText);
        void chart_GetToolTipText(object sender, ToolTipEventArgs e)
        {
            if (e.HitTestResult.ChartElementType == ChartElementType.DataPoint)
            {
                int i = e.HitTestResult.PointIndex;
                DataPoint dp = e.HitTestResult.Series.Points[i];
                e.Text = string.Format("{1:F3}", dp.XValue, dp.YValues[0]);
            }
        }
        private void chart1_MouseMove(object sender, MouseEventArgs e)
        {
            HitTestResult hit = chart1.HitTest(e.X, e.Y);
            if (hit.ChartElementType == ChartElementType.DataPoint)
            {
                if (hit.Series.ChartArea == "ChartArea2")
                {
                    this.Cursor = Cursors.Cross;
                    int i = hit.PointIndex;
                    DataPoint dp = hit.Series.Points[i];

                    double doubleXValue = (dp.XValue);
                    double doubleYValue = dp.YValues[0];
                    //光标
                    hit.ChartArea.CursorX.SetCursorPosition(dp.XValue);
                    //自我实现值的显示       
                    //e.Text = string.Format("{1:F3}", dp.XValue, dp.YValues[0]);
                    textBox1.Text = string.Format("{0:F2}db@{1:F2}Hz", dp.YValues[0], dp.XValue);
                    chart1.Series[1].Points[i].ToolTip = string.Format("{0:F2}db@{1:F2}Hz", dp.YValues[0], dp.XValue);
                    //chart1.Series[1].ToolTip.
                }
            }
            else
            {
                this.Cursor = Cursors.Default;
            }

        }

        private DataPoint getMaxPoint(DataPointCollection dpc, double min, double max)
        {
            if (max > min)
            {
                DataPoint MaxPoint = new DataPoint();
                int n = dpc.Count;
                //找到大于min的最小点的索引
                int start = FindIndex(dpc, min);
                //找到小于max的最大点的索引
                int end = FindIndex(dpc, max);
                MaxPoint = dpc[start];
                for (int i = start; i < max; i++)
                {
                    if (MaxPoint.YValues[0] < dpc[i].YValues[0])
                        MaxPoint = dpc[i];
                }
                return MaxPoint;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 找到增长序列data中大于taget的索引最小的点
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="data"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        private int FindIndex(DataPointCollection dpc, double target)
        {
            int left = 0;
            int right = dpc.Count - 1;
            while (left <= right)
            {
                int mid = (left + right) / 2;
                if (dpc[mid].XValue > target)
                {
                    right = mid - 1;
                }
                else if (dpc[mid].XValue <= target)
                {
                    left = mid + 1;
                }
            }
            return left;
        }

        private void label71_Click(object sender, EventArgs e)
        {

        }

        private void 设置时间ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //TimeSet timeForm = new TimeSet(_iCommunicationService);
            //timeForm.Show();

        }

        private void tabControl2_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateConfigForm();
        }

        private void 指令ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 开始存储数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
<<<<<<< HEAD
            ProgressBar(10);
=======
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
            FlagSave = 1;
            OpenFileDialog dialog = new OpenFileDialog();
            string file = "";
            dialog.Multiselect = true;//该值确定是否可以选择多个文件
            dialog.Title = "请选择文件夹";
            dialog.Filter = "所有文件(*.*)|*.txt";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                file = dialog.FileName;
            }
            PathSave = file;
        }

        private void 结束存储数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
<<<<<<< HEAD
            ProgressBar(10);
=======
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
            FlagSave = 0;
        }

        private void 进入测试模式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Mode = 1;
            //MessageBox.Show("请选择测试通道");
            menuStrip1.Items[4].BackColor = Color.LightBlue;
        }

        private void 退出测试模式ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Mode = 0;
            testHelper.Clear();
            for (int i = 0; i < 32; i++)
            {
                Control ctrl = tableLayoutPanel1.Controls[i];
                SetContrlColor(ctrl, Color.White);
            }
            menuStrip1.Items[4].BackColor = Color.White;
        }
        private void LabelClicked(object sender, EventArgs e)
        {
            //if (Mode == 1 && (ModeEnable & 0b00000011) == 3)
            //{
            //    int id = Convert.ToInt32((sender as Label).Name.Remove(0, 5)) - 1;
            //    if (id < GlobalVariable.ChannelNum)
            //    {
            //        if (!testHelper.IsChoosed(id))
            //        {
            //            (sender as Label).BackColor = Color.LightBlue;
            //            int type = settings.ChannelConfig.Omaplchannels.Channels[id].SensorType;
            //            StringReader sr = new StringReader((sender as Label).Text);
            //            testHelper.ChooseChannel(id, sr.ReadLine(), TypeDictionary[type]);
            //        }
            //        //没被选中
            //        //if (!testHelper.IsChecked[id])
            //        //{
            //        //    (sender as Label).BackColor = Color.LightBlue;
            //        //    testHelper.IsChecked[id] = !testHelper.IsChecked[id];
            //        //}
            //        //选中
            //        //else
            //        //{
            //        //    (sender as Label).BackColor = Color.White;
            //        //    testHelper.IsChecked[id] = !testHelper.IsChecked[id];
            //        //}
            //    }

            //}

        }
        private void SetContrlColor(Control ctrl, Color color)
        {
            if (ctrl.IsHandleCreated && ctrl.InvokeRequired)
            {
                ctrl.Invoke(new Action<Control, Color>(SetContrlColor), ctrl, color);
                return;
            }
            ctrl.BackColor = color;
        }

        private void 开始测试ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            testForm = new TestForm(testHelper.TestCHList);
            testForm.Show();
        }

        private void cb_orbitID_SelectedIndexChanged(object sender, EventArgs e)
        {
            testpoint = cb_orbitID.SelectedIndex + 1;
            //发送配置指令
        }

        private void cb_filter_SelectedIndexChanged(object sender, EventArgs e)
        {
            //发送配置指令
        }

        private void datagrid_octave_1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

<<<<<<< HEAD
      
=======
        private void onDataReceived(NetPacket netPacket)
        {
            //cm.GetDisplacement += ReceivedDispalcement;
            //cm.GetAccData += ReceivedAccData;
            //cm.GetConfig += ReceivedConfig;
            //cm.GetSpeed += ReceivedSpeedData;
            //cm.GetSpeedVol += ReceivedSpeedVol;
            //cm.GetString += ReceivedString;
            //cm.GetSlowSignal += ReceivedSlowSignal;
            //cm.GetMachineTime += ReceiveMachineTime;
            try
            {
                //存储最新的转速包，给DisplacementModel中的字段赋值
                SpeedData rpmsPacket = new SpeedData();
                DateTime time = DateTime.Now;

                switch (netPacket.NetPacketHead.PacketType)
                {
                    case PacketType.DisplacementPacket:
                        #region 接收到位移数据的处理流程
                        //通讯结构体
                        DisplacementData dpt = (DisplacementData)netPacket.DataPacket;
                        ReceivedDispalcement(dpt);

                        #endregion
                        break;
                    case PacketType.AccelerationPacket:
                        //通讯结构体
                        AccData acc = (AccData)netPacket.DataPacket;
                        ReceivedAccData(acc);
                        accDataNow = acc;
                        break;
                    case PacketType.SpeedPacket:
                        //通讯结构体
                        rpmsPacket = (SpeedData)netPacket.DataPacket;
                        ReceivedSpeedData(rpmsPacket);

                        break;
                }
            }
            catch (Exception ex)
            {

                throw;
            }


        }

        private void enable_total_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void enable_low_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }

     

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {

        }

       

        private void tb_all_alarm_KeyPress(object sender, KeyPressEventArgs e)
        {

        }
       
       
        
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895

        private void dbToolStripMenuItem_Click(object sender, EventArgs e)
        {
            axisYUnit = AxisYUnit.db;
        }

        private void ms2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            axisYUnit = AxisYUnit.ms2;
        }

        private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateConfigForm();
        }

        private void tb_angle_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }
        private ListBox _listBox = null;
        private int _selectedIndex = 0;

<<<<<<< HEAD
       


=======
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        private void SaveSelectedIndexOfListBox(ListBox listBox)
        {
            _listBox = listBox;
            _selectedIndex = listBox.SelectedIndex;
        }
        private void listBox1_Leave(object sender, EventArgs e)
        {
            SaveSelectedIndexOfListBox(listBox1);
        }
        private void listBox2_Leave(object sender, EventArgs e)
        {
            SaveSelectedIndexOfListBox(listBox2);
        }

        private void listBox3_Leave(object sender, EventArgs e)
        {
            SaveSelectedIndexOfListBox(listBox3);
        }


        private void tb_name_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_sensitivity_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void cb_rpm_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void cb_sensorType_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_strOptionPin1Name_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_strOptionPin1UpThreshold_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_strOptionPin1DownThreshold_TextChanged(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_strOptionPin2Name_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_strOptionPin2UpThreshold_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_strOptionPin2DownThreshold_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_strOptionPin3Name_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_strOptionPin3UpThreshold_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_strOptionPin3DownThreshold_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_high_warning_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_high_alarm_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_low_warning_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_low_alarm_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_total_warning_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_total_alarm_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_all_warning_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_all_alarm_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_1x_warning_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_1x_alarm_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_2x_warning_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_2x_alarm_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_half_warning_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_half_alarm_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_IP_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_Port_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_strIP1_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_strIP2_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_strIP3_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_strIP4_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_nRefreshIndex_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_rpm_name_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_rpm_angle_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_rpm_virtual_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_key_voltage_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_gear_num_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_gear_voltage_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_name_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_channelvola_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_channelvolb_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_bearhousx_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_bearhousy_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_iniaxlex_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_iniaxley_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_bearhori_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_bearveri_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_strShengJiangSuBeg_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_strShengJiangSuEnd_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_strHeiXiaZiEnd_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_strHeiXiaZiBeg_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_STRHeiXiaZiBeforeEvent_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void tb_tp_strHeiXiaZiAfterEvent_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void cb_rpm_direction_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void cb_tp_channelxindex_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void cb_tp_channelxindey_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void cb_tp_nIndexHour_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void cb_tp_nIndexDay_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void cb_tp_nIndexWeek_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void cb_tp_nIndexMonth_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void cb_tp_nIndexYear_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void cb_tp_nIndexVariableloadDB_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void cb_tp_setiniposflag_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void cb_tp_saveiniposflag_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void rb_gear_manual_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void rb_gear_auto_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void rb_key_manual_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void rb_key_auto_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void cb_nSampleMode_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void enable_total_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void enable_low_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void enable_high_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void enable_all_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void enable_1x_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void enable_2x_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

        private void enable_half_Leave(object sender, EventArgs e)
        {
            this.SaveSettings();
        }

<<<<<<< HEAD
        private void enable_total_CheckedChanged(object sender, EventArgs e)
=======
        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void tb_low_warning_TextChanged(object sender, EventArgs e)
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        {

        }

        private void tb_high_warning_TextChanged(object sender, EventArgs e)
        {

        }
<<<<<<< HEAD
        //加载所有通道报警
        private void button3_Click(object sender, EventArgs e)
        {  
           checkBox1.Checked = true;
            checkBox2.Checked = true;
            checkBox3.Checked = true;
            checkBox4.Checked = true;
            checkBox5.Checked = true;
            checkBox6.Checked = true;
            checkBox7.Checked = true;
            checkBox8.Checked = true;
            checkBox9.Checked = true;
            checkBox10.Checked = true;
            checkBox11.Checked = true;
            checkBox12.Checked = true;
            checkBox13.Checked = true;
            checkBox14.Checked = true;
            checkBox15.Checked = true;
            checkBox16.Checked = true;
            checkBox17.Checked = true;
            checkBox18.Checked = true;
            checkBox19.Checked = true;
            checkBox20.Checked = true;
            checkBox21.Checked = true;
            checkBox22.Checked = true;
            checkBox23.Checked = true;
            checkBox24.Checked = true;
            checkBox25.Checked = true;
            checkBox26.Checked = true;
            checkBox27.Checked = true;
            checkBox28.Checked = true;
            checkBox29.Checked = true;
            checkBox30.Checked = true;
            checkBox31.Checked = true;
            checkBox32.Checked = true; 
            SaveBatchedSet();
            settings.saveXml(settings.Path);

            GetBatchedChannel();
           // button8_Click(sender, e);
        }

        private void button4_Click(object sender, EventArgs e)
        {   
            button3_Click(sender,  e);


        }

        private void button5_Click(object sender, EventArgs e)
        {
           

        }

        private void MainForm_Load(object sender, EventArgs e)
=======

        private void tb_high_alarm_TextChanged(object sender, EventArgs e)
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        {

        }

<<<<<<< HEAD
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            //MessageBox.Show("checkBox1_CheckedChanged");
        }

        private void enable_high_CheckedChanged(object sender, EventArgs e)
=======
        private void tb_low_alarm_TextChanged(object sender, EventArgs e)
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        {

        }

<<<<<<< HEAD
   
        private void savebatched_Click(object sender, EventArgs e)
        {   //保存批量报警信息
            SaveBatchedSet();
            settings.saveXml(settings.Path);
            //统计报警使能信息
            //顺序 高频段 低频段 全频段 标志位 通频阈值 1倍 2倍 0.5倍
            Getenablesetting();
            //统计报警值设定信息
            GetAlarmValue();
            GetBatchedChannel();
            UpdateBatched();

        }
        //加载部分通道报警
        private void button8_Click(object sender, EventArgs e)
        {
            ProgressBar(10);
            int type = cb_sensorType.SelectedIndex;
            for (int id = 0; id < 32; id++)
            {
                if (batched[id] == 1)
                {


                    if (type == 0)//位移通道报警信息设置
                                  //更新数据
                    {
                        settings.ChannelConfig.Omaplchannels.Channels[id].Warning = float.Parse(tb_all_warning.Text);
                        settings.ChannelConfig.Omaplchannels.Channels[id].Alarm = float.Parse(tb_all_alarm.Text);
                        settings.ChannelConfig.Omaplchannels.Channels[id].Enable = enable_all.Checked ? 1 : 0;

                        settings.ChannelConfig.Omaplchannels.Channels[id].Frequency1Warning = float.Parse(tb_1x_warning.Text);
                        settings.ChannelConfig.Omaplchannels.Channels[id].Frequency1Alarm = float.Parse(tb_1x_alarm.Text);
                        settings.ChannelConfig.Omaplchannels.Channels[id].Frequency1Enable = enable_1x.Checked ? 1 : 0;

                        settings.ChannelConfig.Omaplchannels.Channels[id].Frequency2Warning = float.Parse(tb_2x_warning.Text);
                        settings.ChannelConfig.Omaplchannels.Channels[id].Frequency2Alarm = float.Parse(tb_2x_alarm.Text);
                        settings.ChannelConfig.Omaplchannels.Channels[id].Frequency2Enable = enable_2x.Checked ? 1 : 0;

                        settings.ChannelConfig.Omaplchannels.Channels[id].FrequencyHalfWarning = float.Parse(tb_half_warning.Text);
                        settings.ChannelConfig.Omaplchannels.Channels[id].FrequencyHalfAlarm = float.Parse(tb_half_alarm.Text);
                        settings.ChannelConfig.Omaplchannels.Channels[id].FrequencyHalfEnable = enable_half.Checked ? 1 : 0;

                    }
                    else//保存加速度通道报警信息设置
                    {
                        settings.ChannelConfig.Omaplchannels.Channels[id].AccTotalAmplitudeYellowValue = float.Parse(tb_total_warning.Text);
                        settings.ChannelConfig.Omaplchannels.Channels[id].AccTotalAmplitudeRedValue = float.Parse(tb_total_alarm.Text);
                        settings.ChannelConfig.Omaplchannels.Channels[id].AccTotalAmplitudeValueIsUser = enable_total.Checked ? 1 : 0;

                        settings.ChannelConfig.Omaplchannels.Channels[id].AccLowAmplitudeYellowValue = float.Parse(tb_low_warning.Text);
                        settings.ChannelConfig.Omaplchannels.Channels[id].AccLowAmplitudeRedValue = float.Parse(tb_low_alarm.Text);
                        settings.ChannelConfig.Omaplchannels.Channels[id].AccLowAmplitudeValueIsUser = enable_low.Checked ? 1 : 0;

                        settings.ChannelConfig.Omaplchannels.Channels[id].AccHighAmplitudeYellowValue = float.Parse(tb_high_warning.Text);
                        settings.ChannelConfig.Omaplchannels.Channels[id].AccHighAmplitudeRedValue = float.Parse(tb_high_alarm.Text);
                        settings.ChannelConfig.Omaplchannels.Channels[id].AccHighAmplitudeValueIsUser = enable_high.Checked ? 1 : 0;
                        //保存加速度标志位报警
                        settings.ChannelConfig.Omaplchannels.Channels[id].FlagIsUser = enable_alarm.Checked ? 1 : 0;

                    }
                }
            }
            //统计报警使能信息
            //顺序 高频段 低频段 全频段 标志位 通频阈值 1倍 2倍 0.5倍
            settings.saveXml(settings.Path);
            Getenablesetting();
            //统计报警值设定信息
            GetAlarmValue();
            UpdateConfigForm();


        }

        private void sc_alarm_Panel1_Paint(object sender, PaintEventArgs e)
=======
        private void tb_IP_TextChanged(object sender, EventArgs e)
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        {

        }

<<<<<<< HEAD
        private void label150_Click(object sender, EventArgs e)
=======
        private void tb_Port_TextChanged(object sender, EventArgs e)
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
        {

        }

<<<<<<< HEAD
        private void button3_Click_1(object sender, EventArgs e)
        {
            ProgressBar(10);
            int type = cb_sensorType.SelectedIndex;
            for (int id = 0; id < 32; id++)
            {

                if (type == 0)//位移通道报警信息设置
                {
                    //更新数据
                  
                    settings.ChannelConfig.Omaplchannels.Channels[id].Enable = 0;

                 
                    settings.ChannelConfig.Omaplchannels.Channels[id].Frequency1Enable = 0;

                 
                    settings.ChannelConfig.Omaplchannels.Channels[id].Frequency2Enable = 0;

                  
                    settings.ChannelConfig.Omaplchannels.Channels[id].FrequencyHalfEnable = 0;
                    settings.ChannelConfig.Omaplchannels.Channels[id].batched = 0;
                }
                else//保存加速度通道报警信息设置
                {
                  
                    settings.ChannelConfig.Omaplchannels.Channels[id].AccTotalAmplitudeValueIsUser = 0;

                   
                    settings.ChannelConfig.Omaplchannels.Channels[id].AccLowAmplitudeValueIsUser = 0;

                 
                    settings.ChannelConfig.Omaplchannels.Channels[id].AccHighAmplitudeValueIsUser = 0;
                  
                    //保存加速度标志位报警
                    settings.ChannelConfig.Omaplchannels.Channels[id].FlagIsUser = 0;

                    //保存批量修改报警
                    settings.ChannelConfig.Omaplchannels.Channels[id].batched = 0;
                }
            }
            settings.saveXml(settings.Path);
            //统计报警使能信息
            //顺序 高频段 低频段 全频段 标志位 通频阈值 1倍 2倍 0.5倍
            Getenablesetting();
            //统计报警值设定信息
            GetAlarmValue();
            UpdateBatched();
            UpdateConfigForm();
        }

        private void checkBox1_Leave(object sender, EventArgs e)
        {
            SaveBatchedSet();
            settings.saveXml(settings.Path);
            //MessageBox.Show("checkBox1_Leave");
            Getenablesetting();
            //统计报警值设定信息
            GetAlarmValue();
            GetBatchedChannel();
            UpdateBatched();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            ProgressBar(10);
            int type = cb_sensorType.SelectedIndex;
            for (int id = 0; id < 32; id++)
            {

              
                    settings.ChannelConfig.Omaplchannels.Channels[id].batched = 0;
                
            }
            settings.saveXml(settings.Path);
            //统计报警使能信息
            //顺序 高频段 低频段 全频段 标志位 通频阈值 1倍 2倍 0.5倍
            Getenablesetting();
            //统计报警值设定信息
            GetAlarmValue();
            UpdateBatched();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            button3_Click(sender,e);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            button8_Click(sender, e);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            ProgressBar(10);
            int type = cb_sensorType.SelectedIndex;
            for (int id = 0; id < 32; id++)
            {
                if (batched[id] == 1)
                {

                    settings.ChannelConfig.Omaplchannels.Channels[id].SensorType = cb_sensorType.SelectedIndex;
                    settings.ChannelConfig.Omaplchannels.Channels[id].Sensitivity = float.Parse(tb_sensitivity.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].PianYiLiang = float.Parse(tb_offset.Text);

                }
            }
            //统计报警使能信息
            //顺序 高频段 低频段 全频段 标志位 通频阈值 1倍 2倍 0.5倍
            settings.saveXml(settings.Path);
            Getenablesetting();
            //统计报警值设定信息
            GetAlarmValue();
            UpdateConfigForm();
        }

        private void button11_Click(object sender, EventArgs e)
        {
            ProgressBar(10);
            int type = cb_sensorType.SelectedIndex;
            for (int id = 0; id < 32; id++)
            {
                if (batched[id] == 1)
                {
                    settings.ChannelConfig.Omaplchannels.Channels[id].OptionPin1Name = tb_tp_strOptionPin1Name.Text;
                    settings.ChannelConfig.Omaplchannels.Channels[id].OptionPin1UpThreshold = float.Parse(tb_tp_strOptionPin1UpThreshold.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].OptionPin1DownThreshold = float.Parse(tb_tp_strOptionPin1DownThreshold.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].OptionPin2Name = tb_tp_strOptionPin2Name.Text;
                    settings.ChannelConfig.Omaplchannels.Channels[id].OptionPin2UpThreshold = float.Parse(tb_tp_strOptionPin2UpThreshold.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].OptionPin2DownThreshold = float.Parse(tb_tp_strOptionPin2DownThreshold.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].OptionPin3Name = tb_tp_strOptionPin3Name.Text;
                    settings.ChannelConfig.Omaplchannels.Channels[id].OptionPin3UpThreshold = float.Parse(tb_tp_strOptionPin3UpThreshold.Text);
                    settings.ChannelConfig.Omaplchannels.Channels[id].OptionPin3DownThreshold = float.Parse(tb_tp_strOptionPin3DownThreshold.Text);


                }
            }
            //统计报警使能信息
            //顺序 高频段 低频段 全频段 标志位 通频阈值 1倍 2倍 0.5倍
            settings.saveXml(settings.Path);
            Getenablesetting();
            //统计报警值设定信息
            GetAlarmValue();
            UpdateConfigForm();
        }

        private void 灰色ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            menuStrip1.BackColor = Color.Gray;
            statusStrip1.BackColor = Color.Gray;
            tabPage1.BackColor = Color.Gray;
        }

        private void 蓝色ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            menuStrip1.BackColor = Color.Blue;
            statusStrip1.BackColor = Color.Blue;
            tabPage1.BackColor= Color.Blue; 
        }

        private void 白色ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            menuStrip1.BackColor = Color.White;
            statusStrip1.BackColor = Color.White;
            tabPage1.BackColor = Color.White;
        }

        private void 绿色ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            menuStrip1.BackColor = Color.Green;
            statusStrip1.BackColor = Color.Green;
            tabPage1.BackColor = Color.Green;
        }

        private void 黑色ToolStripMenuItem_Click(object sender, EventArgs e)
        {
          //  menuStrip1.BackColor = Color.Blue;
            statusStrip1.BackColor = Color.Black;
            tabPage1.BackColor = Color.Black;
        }

        private void 是ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            save = true;
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            //默认路径为电脑路径


            dialog.Description = "请选择保存路径";

            
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                foldPath =dialog.SelectedPath;


            }
            Console.WriteLine("导出目录为" + foldPath);
            textBox3.Text = foldPath;
        }

        private void 否ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            save = false;
        }
    }
=======
        private void tb_IP_KeyPress(object sender, KeyPressEventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void tb_all_warning_TextChanged(object sender, EventArgs e)
        {

        }

        private void tb_all_alarm_TextChanged(object sender, EventArgs e)
        {

        }

        private void enable_all_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void enable_1x_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void enable_2x_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void enable_half_CheckedChanged(object sender, EventArgs e)
        {

        }
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
    }

    public class TxtOperate
    {
        public static void AppendLine(string path, string content)
        {
            FileStream fs = new FileStream(path, FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);
            //开始写入
            sw.WriteLine(content);
            //sw.Write(content);
            //清空缓冲区
            sw.Flush();
            //关闭流
            sw.Close();
            fs.Close();
        }
    }

    public class AutoRefresh
    {
        public AccData accData { get; set; }
        private bool flag = false;
        public Task task;

        public async void StartRefresh()
        {
            flag = true;
            await Task.Run(() =>
              {
                  while (flag)
                  {
                      if (accData.CHAccData != null)
                      {
                          for (int i = 0; i < accData.CHAccData.Length; i++)
                          {
                              Random rd = new Random();
                              accData.CHAccData[i].TotalDB += (Convert.ToSingle(rd.Next(100)) / 200.0f);
                          }
                      }
                  }
              });
        }

        public void StopRefresh()
        {
            flag = false;
        }
    }

<<<<<<< HEAD

=======
}
>>>>>>> b19c74022a89f58c8c960e2031f2461983bbb895
